package com.hugoo.imp.slt;

import java.util.LinkedList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 导入文件队列
 *
 * @author Lovelock.Chan
 */
public class ImpQueue {

    private static final LinkedList<String> queue = new LinkedList();
    private final static Log log = LogFactory.getLog(ImpQueue.class);
    private static final ImpQueue ref = new ImpQueue();

    private ImpQueue() {
    }

    public static ImpQueue ref() {
        return ref;
    }

    public synchronized String getCode() {
        while (queue.size() <= 0) {
            try {
                wait();
            } catch (Exception e) {
                log.info("...", e);
            }
        }
        queue.clear();
        return "";
    }

    public synchronized void putCode(String code) {
        queue.addLast(code);
        notifyAll();
    }
}
